/*
  Losu Copyright Notice
  --------------------
    Losu is an open source programming language project under the MIT license
  that can be used for both academic and commercial purposes. There are no
  fees, no royalties, and no GNU-like "copyright" restrictions. Losu qualifies
  as open source software. However, Losu is not public property, and founder
  'chen-chaochen' retains its copyright.

    Losu has been registered with the National Copyright Administration of the
  People's Republic of China, and adopts the MIT license as the copyright
  licensing contract under which the right holder conditionally licenses its
  reproduction, distribution, and modification rights to an unspecified public.

    If you use Losu, please follow the public MIT agreement or choose to enter
  into a dedicated license agreement with us.

  The MIT LICENSE is as follows
  --------------------
  Copyright  2020 - now  chen-chaochen

    Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the “Software”), to
  deal in the Software without restriction, including without limitation the
  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  sell copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
*/

/*
    This document is part of the Losu Community OSPP - 2024 subject results
  contributed by Dongqiao Huang @ NEUQ, following MIT LICENSE Contributed to
  the Losu Community.

  The MIT LICENSE is as follows
  --------------------
  Copyright 2024 Dongqiao Huang

    Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the “Software”), to
  deal in the Software without restriction, including without limitation the
  rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  sell copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
 */

/*
  This file is about liblosuh's API, which is a library for the losuh
  */

#include "losuh.h"

void
__losuhAPI_regNumber (LosuVm *vm, const char *name, _l_number num)
{
  vm_setval (vm, name, obj_newnum (vm, num));
}

void
__losuhAPI_regString (LosuVm *vm, const char *name, const char *str)
{
  vm_setval (vm, name, obj_newstr (vm, (char *)str));
}

void
__losuhAPI_regFunc (LosuVm *vm, const char *name, LosuApi func)
{
  vm_setval (vm, name, obj_newfunction (vm, func));
}

void
__losuhAPI_regScript (LosuVm *vm, const char *name, const char *byte,
                      size_t len)
{
  vm_dobyte (vm, byte, len, name);
}

void
__losuhAPI_regObject (LosuVm *vm, const char *name, LosuObj obj)
{
  vm_setval (vm, name, obj);
}

void
__losuhAPI_regClass (LosuVm *vm, const char *name, LosuObj cls)
{
  obj_setunitbystr (vm, cls, "::type", obj_newstr (vm, (char *)name));
  vm_setval (vm, name, cls);
}

void
__losuhAPI_regObjNumber (LosuVm *vm, LosuObj obj, const char *name,
                         _l_number num)
{
  obj_setunitbystr (vm, obj, (char *)name, obj_newnum (vm, num));
}
void
__losuhAPI_regObjString (LosuVm *vm, LosuObj obj, const char *name,
                         const char *str)
{
  obj_setunitbystr (vm, obj, (char *)name, obj_newstr (vm, (char *)str));
}

void
__losuhAPI_regObjObject (LosuVm *vm, LosuObj obj, const char *name,
                         LosuObj obj2)
{
  obj_setunitbystr (vm, obj, (char *)name, obj2);
}

void
__losuhAPI_regObjClass (LosuVm *vm, LosuObj obj, const char *name,
                        const char *type, LosuObj cls)
{
  obj_setunitbystr (vm, cls, "::type", obj_newstr (vm, (char *)type));
  obj_setunitbystr (vm, obj, (char *)name, cls);
}

void
__losuhAPI_regObjFunc (LosuVm *vm, LosuObj obj, const char *name, LosuApi func)
{
  obj_setunitbystr (vm, obj, (char *)name, obj_newfunction (vm, func));
}